<?php

	header('Content-Type:text/html;charset="utf-8"');
	//定义移动上传文件的目录
	define('UPLOAD_FILE_PATH','upload/');
	function upload_file()
	{
		//$upload_tmp_dir = ini_get('upload_tpm_dir');
		$is_hidden = $_POST['hidden'];
		//print_r($is_hidden);
		if ($is_hidden=='true')
		{
			if ($_FILES['file']['error'] > 0)
			{
				echo '上传出现错误: '.$_FILES['file']['error'].'<br />';
			}
			else
			{
				echo '上传的文件名: '.$_FILES['file']['name'].'<br />';
				echo '上传的文件类型: '.$_FILES['file']['type'].'<br />';
				echo '上传的文件大小: '.$_FILES['file']['size'].'<br />';
				echo '上传的文件临时路径: '.$_FILES['file']['tmp_name'].'<br />';
				if (is_file(UPLOAD_FILE_PATH.$_FILES['file']['name']))
				{
					echo $_FILES['file']['name'].'该文件已经存在!';
				}
				else
				{
					//移动上传的文件到指定的目录
					if (move_uploaded_file($_FILES['file']['tmp_name'],UPLOAD_FILE_PATH.$_FILES['file']['name']))
					{
						//取文件的扩展名
						$file_info = pathinfo(UPLOAD_FILE_PATH.$_FILES['file']['name'],PATHINFO_EXTENSION);
						//得到新的文件名(根据当前的时间)
						$new_file = UPLOAD_FILE_PATH.date('YmdHis').'.'.$file_info;
						//重命名上传的文件
						rename(UPLOAD_FILE_PATH.$_FILES['file']['name'],$new_file);
						echo $_FILES['file']['name'].'被移动到'.$new_file.'<br />';
						echo '<a href="javascript:history.go(-1)">在添加</a>';
					}
				}
			}
		}
		else
		{
			echo '文件上传不成功!';
		}
	}
	upload_file();
?>